package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.product.service.ManageService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Fxz
 * @version 1.0
 * @date 2022-02-04 17:37
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/admin/product")
@RequiredArgsConstructor
public class BaseManageController {

	private final ManageService manageService;

	/**
	 * 查询所有一级分类
	 * @return 所有一级分类
	 */
	@GetMapping("/getCategory1")
	public Result<List<BaseCategory1>> getCategory1() {
		return Result.ok(manageService.getBaseCategory1());
	}

	/**
	 * 根据一级分类Id查询所有二级分类
	 * @return 所有二级分类
	 */
	@GetMapping("/getCategory2/{category1Id}")
	public Result<List<BaseCategory2>> getCategory2(@PathVariable("category1Id") Long category1Id) {
		return Result.ok(manageService.getBaseCategory2(category1Id));
	}

	/**
	 * 根据二级分类Id查询所有三级分类
	 * @return 所有三级分类
	 */
	@GetMapping("/getCategory3/{category2Id}")
	public Result<List<BaseCategory3>> getCategory3(@PathVariable("category2Id") Long category2Id) {
		return Result.ok(manageService.getBaseCategory3(category2Id));
	}

	/**
	 * 根据分类id 查询平台属性集合
	 * @param category1Id
	 * @param category2Id
	 * @param category3Id
	 * @return
	 */
	@GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
	public Result<List<BaseAttrInfo>> attrInfoList(@PathVariable("category1Id") Long category1Id,
			@PathVariable("category2Id") Long category2Id, @PathVariable("category3Id") Long category3Id) {
		return Result.ok(manageService.getBaseAttrInfo(category1Id, category2Id, category3Id));
	}

	/**
	 * 保存平台属性/修改
	 * @return
	 */
	@PostMapping("/saveAttrInfo")
	public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo) {
		manageService.saveAttrInfo(baseAttrInfo);
		return Result.ok();
	}

	/**
	 * 根据平台属性id获取平台属性值
	 * @param attrId
	 * @return
	 */
	@GetMapping("getAttrValueList/{attrId}")
	public Result getAttrValueList(@PathVariable Long attrId) {
		return Result.ok(manageService.getAttrValueList(attrId));
	}

}
